<#--忽略理由浮层 begin-->
<div id="cancel-pop" style="display:none;">
    <div id="for-cancel">
        <p>请选择忽略理由：</p>
        <ul>
            <li><a href="javascript:void(0)" why="salary" rid="3">薪资不满意</a></li>
            <li><a href="javascript:void(0)" why="city" rid="2">工作地点不符</a></li>
            <li><a href="javascript:void(0)" why="type" rid="4">职位类别不符</a></li>
            <#if isIntern?? && isIntern && job.kind?? && job.kind== '3'>
            <li><a href="javascript:void(0)" why="time" rid="7">实习时间不符</a></li>
            </#if>
            <li><a href="javascript:void(0)" why="other" rid="6">我想说点别的</a></li>
        </ul>
    </div>
</div>
<#if userIntention??>
<div id="cancel-salary-win" style="display:none;">
    <div class="cancel-lay" style="_height:150px; min-height:150px;">
        <h1><span>忽略成功！</span></h1>
    </div>
</div>
<div id="cancel-city-win" style="display:none;">
    <div class="cancel-lay" style="_height:150px; min-height:150px;">
        <h1><span>忽略成功！</span></h1>
    </div>
    </div>
</div>
<div id="cancel-type-win" style="display:none;">
    <div class="cancel-lay" style="_height:126px; min-height:126px;">
        <h1><span>忽略成功！</span></h1>
    </div>
</div>
<div id="cancel-time-win" style="display:none;">
    <div class="cancel-lay" style="_height:150px; min-height:150px;">
        <h1><span class="yahei">忽略成功！</span></h1>
        <div class="left">
            <p class="b">选择期望的实习时间可收到更合适的邀请。</p>
            <div class="lay">
                <table class="dj-form-smart th-left">
                    <tr>
                        <th>期望实习时间：</th>
                        <td>
                            <input id="internStartYear" type="text" reg="fun:$.formValidateFn.time,try,td" maxlength="4" class="text J_checkTime " style="width:40px" <#if userIntention.internStartDate?? >value="${userIntention.internStartDate?string('yyyy')}"</#if>> 年 <input id="internStartMonth" type="text" class="text J_m" style="width:30px" <#if userIntention.internStartDate?? >value="${userIntention.internStartDate?string('MM')}"</#if>> 月 至 <input id="internEndYear" type="text"  class="text J_y" style="width:40px" <#if userIntention.internStartDate?? >value="${userIntention.internEndDate?string('yyyy')}"</#if>> 年 <input id="internEndMonth" type="text" class="text J_m" style="width:30px" <#if userIntention.internStartDate?? >value="${userIntention.internEndDate?string('MM')}"</#if>> 月
                            <div style="display:none;" class="J_Error">请填写期望实习时间</div>
                        </td>
                    </tr>
                    <tr>
                        <th>每周实习天数：</th>
                        <td>
                <select id="internshipDays">
                    <option value="0">请选择</option>
                    <#list 2..5 as day>
                        <option value="${day}" <#if (userIntention.internshipDays)?? && (userIntention.internshipDays) == day> selected="selected"</#if>>${day}天</option>
                    </#list>
                </select>
                            <div style="display:none;" class="J_Error">请选择实习时间</div>
                        </td>
                    </tr>
                </table>
                <em id="J_timeSubmit" class="timeValidate"></em>
        </div>
            <script type="text/javascript">
                $(function() {
                    var $checks = $('.J_checkTime '),
                            $btnO = $('#J_timeSubmit');
                    $checks.formValidate({button: 'timeValidate'});
                    $checks.focus(function () {
                        $(this).parents('td').find('.J_Error').hide();
                    });
                    $('.J_y,.J_m').focus(function () {
                        $(this).parents('td').find('.J_Error').hide();
                    });
                    $('.J_addBar').click(function () {
                        $(this).parents('td').find('.J_Error').hide();
                    });
                    $btnO.click(function (e) {
                        e.preventDefault();
                        var flag = true;
                        $checks.each(function () {
                            var e = $.formValidate.check('timeValidate', this);
                            if (!e) {
                                $(this).parents('td').find('.J_Error').show();
                            }
                        });

                        if ($('#internshipDays').val() == '0') {
                            $('#internshipDays').parent('td').find('.J_Error').show();
                            flag = false;
                        }
                        if (!$.formValidate.check('timeValidate') || !flag) {
                            $btnO.data('finalFlag',false)
                        }else{
                            $btnO.data('finalFlag',true)
                        }
                    });
                    $('#internshipDays').change(function(){
                        $(this).parent('td').find('.J_Error').hide();
                    })
                });
            </script>
    </div>
    </div>
</div>
<div id="cancel-other-win" style="display:none;">
    <div class="cancel-lay" style="_height:126px; min-height:126px;">
        <div class="left">
            <p class="b" style="padding-top:24px;">填写你不喜欢的原因<em style="color: #666666">（2-10个字）</em></p>
            <p><input id="other-text" type="text" class="text" style="width: 275px;height: 22px;" maxlength="10"><br/><span id="other-text-alert" class="red" style="display:none;padding-top: 3px;">请输入2-10个字</span></p>
        </div>
    </div>
</div>
</#if>

<div id="regions-dialog" style="display:none;">
<#assign maxSelect = 5>
        <#assign allowSelectProvince = true>
        <#--<#include "/WEB-INF/ftl/common/dialog-regions.ftl" />-->
</div>
<div id="profession1-dialog" style="display:none;"></div>
<div id="for-cancel-smart" style="display:none;" class="dj-tips-base dj-tips-smart arrow-b">
    <span class="arrow arrow-r"></span>
    <a class="remove" href="javascript:void(0)">关闭</a>
    <div class="shadow" style="">
        <div class="inn-con">
            此操作不会反馈给HR，只用于优化<br/>你的职位邀请。&emsp;&emsp;&emsp;<a id="close-pop" href="javascript:void(0)" class="green">我知道了</a>
        </div>
    </div>
</div>
<@holder>
<script type="text/javascript">
$(function() {
    var $cancelTips = $('#for-cancel'),
        cancelTips = 'for-cancel',
        $cancelBtn = $('#btn-cancel'),
        cancelbtn = 'btn-cancel',
        cancelwin = {
            salary : '#cancel-salary-win',
            city : '#cancel-city-win',
            type : '#cancel-type-win',
            time : '#cancel-time-win',
            other : '#cancel-other-win'
        },
        defaultArgs = function() {
            return {
                mask  : true,
                title : '大街网提示',
                    width : 520,
                mercy : false
            }
        };
    $cancelTips.find('a').click(function() {
        $(document).unbind('click', globeClick);
        $cancelPop.hide();
        var why = $(this).attr('why');
        cancelRequest($(this).attr('rid'));
        switch (why) {
            case 'salary' :
                var salaryArgs = defaultArgs();
                salaryArgs['oncomplete'] = salaryfun;
                $.dialog(cancelwin['salary'], salaryArgs);
                break;
            case 'city' :
                var cityArgs = defaultArgs();
                cityArgs['oncomplete'] = cityfun;
                $.dialog(cancelwin['city'], cityArgs);
                break;
            case 'type' :
                var typeArgs = defaultArgs();
                typeArgs['oncomplete'] = typefun;
                $.dialog(cancelwin['type'], typeArgs);
                break;
            case 'time' :
                var timeArgs = defaultArgs();
                timeArgs['oncomplete'] = timefun;
                $.dialog(cancelwin['time'], timeArgs);
                break;
            case 'other' :
                var otherArgs = {mask:true, title:'大街网提示', width:420, mercy:false};
                otherArgs['oncomplete'] = otherfun;
                $.dialog(cancelwin['other'], otherArgs);
                break;
            default:
                break;
        }
        return false;
    });
    function globeClick(e) {
        var $t = $(e.target),
            bol = e.target.id == cancelbtn || $t.parents('#' + cancelTips).length || $t.parents('#' + cancelbtn).length
        if (!bol) {
            $(document).unbind('click', globeClick);
            $cancelPop.hide();
        }
    }
    <#if leftDays?? && leftDays gt 0>
    $(function() {
        if (!isPop()) {
            return
        }
        var $cancelBtn = $('#btn-cancel'),
            $tips = $('#for-cancel-smart');
        var pos_btn = $cancelBtn.position();
        $tips.show().css({
            'left' : pos_btn.left - 124,
            'top' : pos_btn.top - 75
        });
        $(window).resize(function() {
            if ($tips.css('display') == 'none') return;
            var pos_btn = $cancelBtn.position();
            $tips.css({
                'left' : pos_btn.left - 124,
                'top' : pos_btn.top - 75
            });
        });
        $cancelBtn.click(function() {
            $tips.hide();
        });
        $tips.find('.remove').click(function() {
            $tips.hide();
            $.cookie('invite_pop', '1', { expires:300 , path: '/', domain: '${configs["domains.root"]}' });
        });
        $('#close-pop').click(function() {
            $tips.find('.remove').click();
        });
    });
    </#if>
    function isPop() {
        var invite_pop_cookie = $.cookie('invite_pop');
        return !(invite_pop_cookie != null && invite_pop_cookie == 1);
    }
});

// 忽略
var cancelRequest = function(rid) {
    $.post("/invitation/ignore", {"id":${id!0},"reason":rid,"tracking_id":"${(loginUser.uid)!}_0_${(job.jid)!}"}, function(r) {
        if (r.substr(0, 1) != '0') {
            alert(r.substr(2));
        } else {
            if (window.name == 'notice${id!0}') {
                try{
                    window.opener.remove_by_id(${id!0});
                }catch(e){
                }
            }
            var date = new Date();
            var href = "http://${configs['domains.job']}/intention/index";
            $('#refuse').html('<em>你已于 ' + date.getFullYear() + '年' + (date.getMonth() + 1) + '月' + date.getDate() + '日' + ' 忽略了该职位邀请。</em>');<#--<a class="big-normal" onclick="window.close();return false;" href="javascript:void(0);"><span>关闭本页</span></a>-->
            $('#refuse').show();
            $('#no_op').hide();
        }
    });
};

var $isIntern=<#if isIntern?? && isIntern>true<#else>false</#if>;
var salaryfun = function(){
    var $salary = $('#salary').val();
    if ($salary > 0) {
        $.post('/invitation/refuse?t=1', {salary:$salary, isIntern:$isIntern});
    }
};
// 城市不适合
var cityfun = function() {
    var $thinkOther = $('#other-citys').attr("checked") == true ? 1 : 0;
    var $city = $('#regions-hidden').val();
    if($city == ''){
        $(this).parent().find('.J_Error').show();
        return false;
    }
    $.post('/invitation/refuse?t=2', {city:$city, thinkOther:$thinkOther, isIntern:$isIntern});
};

// 不喜欢这类职位
var typefun = function() {
    var $thinkOther = $('#other-professions').attr("checked") == true ? 1 : 0;
    if ($('#industry-button').data('considerFinalData')!=0 && $('#industry-button').data('considerFinalData').ids.length != 0) {
        $('#consider-industry-profession').val($('#industry-button').data('considerFinalData').ids);
    } else {
        $('#industry-button').parent().find('.J_Error').show();
        return false;
    }
    var $profession = $('#consider-industry-profession').val();
    $.post('/invitation/refuse?t=3', {profInd:$profession, thinkOther:$thinkOther, isIntern:$isIntern});
};

// 时间
$('#regions-input').mousedown(function() {
    $(this).attr("disable",true);
    $('#regions-link').click();
});
$('#regions-input').focus(function () {
    $(this).blur();
});

var timefun = function() {
    $('#J_timeSubmit').click();
    if (!$('#J_timeSubmit').data('finalFlag')) {
        return false;
    }
    var $internshipDays = $('#internshipDays').val();
    var $startDate = $("#internStartYear").val() + "-" + $("#internStartMonth").val() + "-01";
    var $endDate = $("#internEndYear").val() + "-" + $("#internEndMonth").val() + "-01";
    $.post('/invitation/refuse?t=4', {internshipDays:$internshipDays,internStartDate:$startDate,internEndDate:$endDate});
};

// 其他
var otherfun = function() {
    var $text = $('#other-text'),
            $alert = $('#other-text-alert'),
            text = $.trim($text.val()),
            reg = /^.{2,10}$/;
    if (text != "" && reg.test(text)) {
        var $reason = $('#other-text').val();
        $.post('/invitation/refuse?t=5', {reason:$reason,jid:"${job.jid}"});
        $alert.hide();
    } else {
        $alert.css('display', 'block');
        return false;
    }
};

// 添加删除城市
$(function() {
    if($('#regions-hidden').val()!=''){
        var tempData = $('#regions-input').val().split('+');
        $('#city-other-record').val('1');  //原来有值
    } else {
        var tempData = [];
        $('#city-other-p').hide();
        $('#other-citys').attr('checked', false);
        $('#city-other-record').val('0');
    }
    if (!tempData.length == 0) {
        requestResultOneStep('regions',tempData);
    }
    $('#regions-link').pickpad({title: '请选择期望的工作城市', width: 600,oncomplete:function(){
        $('#regions-link').parent().find('.J_Error').hide();
        var data = $('#regions-input').val().split('+');
        requestResultOneStep('regions',data);
        setRegionsProperty();
        return false;
    }
    });
    $('#regions-result .delete').live('click', function() {
        deleteDateOneStep($(this),'regions');
        setRegionsProperty();
    });
    function setRegionsProperty() {
        var $p = $('#city-other-p'),
                $check = $('#other-citys'),
                $record = $('#city-other-record');
        if ($('#regions-hidden').val().length == 0) {
            $p.hide();
            $check.attr('checked', false);
            $record.val('0');
        } else {
            if ($record.val() == '0') {
                $check.attr('checked', true);
                $p.show();
            }
            $record.val('1');
        }
    }
});

// 其他
$(function() {
    var $input = $('#other-text'),
        $alert = $('#other-text-alert');
    $input.focus(function() {
        $alert.hide();
    });
    $input.blur(function() {
        var text = $input.val(),
                reg = /^.{2,10}$/;
        if (reg.test(text)) {
            $alert.hide();
        } else {
            $alert.css('display', 'block');
            return false;
        }
    });
});
</script>
</@holder>
<#--忽略理由浮层 end-->
<div id="industry-dialog" style="display:none;"></div>
<div id="profession-dialog" style="display:none;"></div>
<@holder>
<script type="text/javascript">
    (function() {
        <#assign loadUrl = '/ajax/load/dialog/newregion?q.maxSelect=5&q.kod=industry'/>
        $('#industry-dialog').load('${loadUrl}', function() {
            $('#industry-link').pickpad({title:'请选择期望从事的领域',button:'下一步',width:700,clearData:true,minData:1,oncomplete:function() {
                __populatePositions($('#industry-hidden').val().split(','));
                $('#profession-link').click();
            }
            });
        });
        <#assign loadUrl = '/ajax/load/dialog/newprofession?q.maxSelect=3&q.kod=profession'/>
        $('#profession-dialog').load('${loadUrl}', function() {
            $('#profession-link').pickpad({title:'请选择期望从事的职类',width:700,clearData:true,minData:1,oncomplete:function() {
                var positionsFinalResult = resultJoin('industry', 'profession');
                $('#industry-button').data('considerFinalData', positionsFinalResult);//positionsFinalData:最后取数据的关键字
                if ($('#industry-button').data('considerFinalData').ids.length == 0) {
                    $('#profession-other-p').hide();
                    $('#other-professions').attr('checked', false);
                    $('#profession-other-record').val('0');
                } else {
                    if ($('#profession-other-record').val() == '0') {
                        $('#other-professions').attr('checked', true);
                        $('#profession-other-p').show();
                    }
                    $('#profession-other-record').val('1');
                }
            }});
        });
    })();
</script>
</@holder>